//
//  QForgetPayPassWordVC.m
//  QoilPublic
//
//  Created by 杨凯 on 16/11/16.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QForgetPayPassWordVC.h"
#import "QSetUpPassWordVC.h"
@interface QForgetPayPassWordVC ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTetxtField;

@property (weak, nonatomic) IBOutlet UITextField *authCodeTextField;


@end

@implementation QForgetPayPassWordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"重置支付密码";
    [self setupForDismissKeyboard];
    [QViewUtility setupNavigationBarBackForController:self backSelector:@selector(forgetPayback)];

}

- (void)forgetPayback{

    if(self.block){
        self.block();
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)getAuthCodeAction:(id)sender {
    UIButton *button = (UIButton *)sender;
    if(_phoneTetxtField.text.length == 11){
        [QParamService onTimer:button type:NO];
        [self requestAuthCodel];
    }else{
        [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"请输入正确手机号" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
    }

}

- (IBAction)agreeAction:(id)sender {
    if(_authCodeTextField.text.length == 6){
        [self requestData];
    }else{
        [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"请输入正确手机号" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];

    }
}

- (void)requestData{

    NSString *url = [QParamService urlWithAction:@"verificationCode"];
    NSDictionary *param = [QParamService forgetPayPassword:_authCodeTextField.text];
    [[QHttpManager sharedManager] POST:url parameterMD5:param completion:^(NSData *data, NSDictionary *dict, NSError *error) {
        if(error){
            return ;
        }
        QBaseModel *basModel = [QBaseModel objectFromDict:dict];
        if([basModel.result isEqualToString:@"success"]){
            QSetUpPassWordVC *vc = [[QSetUpPassWordVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:basModel.errMsg btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }
    }];
}

#pragma mark-----请求验证码接口
- (void)requestAuthCodel{
    NSString *url = [QParamService urlWithAction:@"getVerificationCode"];
    NSDictionary *param = [QParamService getauthcodetel:_phoneTetxtField.text type:@"3"];
    [[QHttpManager sharedManager] POST:url parameterMD5:param completion:^(NSData *data, NSDictionary *dict, NSError *error) {
        if(error){
            return ;
        }
        QBaseModel *basModel = [QBaseModel objectFromDict:dict];
        if([basModel.result isEqualToString:@"success"]){
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"smile_image"] content:@"验证码已发送,请注意查收" btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:basModel.errMsg btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }
    }];
}



@end
